package com.baseweb.webadmin.core.model.mapper;

import com.baseweb.webadmin.core.model.Sql.SqlProvider;
import com.baseweb.webadmin.core.model.pojo.Dict;
import com.baseweb.webadmin.core.util.RequestPage;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by zx on 2017/8/10.
 */
public interface DictMapper {
    @Delete({
            "delete from dict",
            "where id = #{id,jdbcType=INTEGER}"
    })
    Integer deleteByPrimaryKey(Integer id);

    @Select({
            "select",
            "id, type, name, code",
            "from dict",
            "where id = #{id,jdbcType=INTEGER}"
    })
    @ResultMap("BaseResultMap")
    Dict selectByPrimaryKey(Integer id);

    @Insert({
            "insert into dict (type, name, code)",
            "values (#{type,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR},#{code,jdbcType=INTEGER}) "
    })
    @SelectKey(statement="SELECT LAST_INSERT_ID()", keyProperty="id", before=false, resultType=Integer.class)
    Integer insert(Dict record);

    @Update({
            "update dict",
            "set code = #{code,jdbcType=INTEGER},",
            "name = #{name,jdbcType=VARCHAR} ",
            "where id = #{id,jdbcType=INTEGER}"
    })
    Integer updateByPrimaryKey(Dict record);

    @SelectProvider(type = SqlProvider.class,method = "selectDictListByPage")
    @ResultMap("BaseResultMap")
    List<Dict> selectDictListByPage(@Param("type")Integer type, @Param("page")RequestPage page);

    @SelectProvider(type = SqlProvider.class,method = "countDictListByPage")
    Integer countDictListByPage(@Param("type")Integer type, @Param("page")RequestPage page);
}
